package indi.zhifa.study2025.class004.imgserv.controller;

import indi.zhifa.engine.core.common.web.ann.ZhiFaRestController;
import indi.zhifa.study2025.class004.imgserv.entity.dto.PictureRequest;
import indi.zhifa.study2025.class004.imgserv.entity.vo.PictureVo;
import indi.zhifa.study2025.class004.imgserv.service.IImageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@Slf4j
@Validated
@RequiredArgsConstructor
@Tag(name = "图片接口")
@ZhiFaRestController
@RequestMapping("/pictureMgr")
public class PictureController {

    final IImageService mIImageService;

    @Operation(summary = "上传文件")
    @PostMapping("/upload/file")
    public PictureVo upload(@RequestPart("file") MultipartFile pFile) throws IOException {
        PictureVo rtn = mIImageService.uploadFromFile(pFile);
        return rtn;
    }

    @Operation(summary = "上传url")
    @PostMapping("/upload/url")
    public PictureVo upload(@RequestBody PictureRequest pPictureRequest) throws IOException {
        PictureVo rtn = mIImageService.uploadFromUrl(pPictureRequest);
        return rtn;
    }


}
